<?php

namespace oa\models;

use yii\base\Model;

class BaseForm extends Model
{
    public $patterns = [
        'int' => ['/^[1-9]\d{0,3}$/', '必须输入整数'],
        'int_g' => ['/^[1-9]\d{0,3}$/', '必须输入正整数'],
        'int_eg' => ['/^[1-9]\d{0,3}$/', '必须输入不小于零的整数'],
        'int_l' => ['/^[1-9]\d{0,3}$/', '必须输入负整数'],
        'int_el' => ['/^[1-9]\d{0,3}$/', '必须输入不小于零的整数'],
    ];

    public $messages = [
        'int' => '/^[1-9]\d{0,3}$/',
        'int_g' => '/^[1-9]\d{0,3}$/',
        'int_eg' => '/^[1-9]\d{0,3}$/',
        'int_l' => '/^[1-9]\d{0,3}$/',
        'int_el' => '/^[1-9]\d{0,3}$/',
    ];

    public function getOneError()
    {
        $errors = $this->getErrors();
        if (!empty($errors)) {
            foreach ($errors as $k => $v) {
                return $v[0];
            }
        }
        return '';
    }
}
